package com.yh.homestay.controller;

import com.yh.homestay.common.DriverEditResult;
import com.yh.homestay.common.HomeStayResult;
import com.yh.homestay.pojo.GuestsDriver;
import com.yh.homestay.service.GuestsDriverService;
import com.yh.homestay.utils.QiNiuUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class GuestsDriverController {
    @Autowired
    private GuestsDriverService driverService;

    @RequestMapping(value="/driverList",produces = "application/json; charset=utf-8")
    @ResponseBody
    public HomeStayResult selectAll(Integer page, Integer limit, String driverName){
        HomeStayResult selectall = driverService.selectall(page, limit,driverName);
        return selectall;
    }

    @RequestMapping("/driver/del/{id}")
    @ResponseBody
    public HomeStayResult deleteById(@PathVariable Integer id){
        HomeStayResult delete = driverService.delete(id);
        return delete;
    }

    @RequestMapping("/addDriver")
    @ResponseBody
    public HomeStayResult addDriver(GuestsDriver guestsDriver){
        guestsDriver.setDriverDrivingPic(QiNiuUtil.qiniu_img_url_pre+guestsDriver.getDriverDrivingPic());
        guestsDriver.setDriverIdcardA(QiNiuUtil.qiniu_img_url_pre+guestsDriver.getDriverIdcardA());
        guestsDriver.setDriverIdcardB(QiNiuUtil.qiniu_img_url_pre+guestsDriver.getDriverIdcardB());
        HomeStayResult homeStayResult = driverService.addDriver(guestsDriver);
        return homeStayResult;
    }
    @RequestMapping("/driver-edit/{id}")
    @ResponseBody
    public HomeStayResult editDriver(@PathVariable Integer id, String driverName, String driverPhone, String driverDrivingCreateTime, String driverDrivingExpiredTime, String driverDrivingPic, String driverIdcardA, String driverIdcardB, String driverDrivingType, Integer driverStatus){
        HomeStayResult update = driverService.update(id,driverName,driverPhone,driverDrivingCreateTime,driverDrivingExpiredTime,driverDrivingPic,driverIdcardA,driverIdcardB,driverDrivingType,driverStatus);
        return update;
    }

    @RequestMapping("/driver-edit/selectOne/{id}")
    @ResponseBody
    public DriverEditResult editDriver(@PathVariable Integer id){
        DriverEditResult editResult = driverService.selectOne(id);
        return editResult;
    }
    @RequestMapping("/driver-deleteAll")
    @ResponseBody
    public HomeStayResult deleteSelectDriver(@RequestParam List<Integer> ids){
        HomeStayResult editResult = driverService.deleteAll(ids);
        return editResult;
    }

}

